package 第4节面向对象;
//自定义栈 底层是由顺序表实现
public class ArrayStack<E> {
    private ArrayList<E> list;

    public ArrayStack() {
        list = new ArrayList<>();
    }
    //入栈
    public void push(E element) {
        list.add(element);
    }
    //出栈
    public E pop() {
        return list.delete(list.size() - 1);
    }
    //查看栈顶
    public E peek() {
        return list.get(list.size() - 1);
    }

    public void clear() {
        list.clear();
    }

    @Override
    public String toString() {
        return list.toString();
    }
}
